﻿<%@ Page language="c#" Inherits="Mysoft.Crm.Web.Controls.Lookup.LookupMultiPage" CodeBehind="Mysoft.Crm.Application.Pages.Controls.dll" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Crm.Application.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Register TagPrefix="frm" Namespace="Mysoft.Crm.Application.Forms" Assembly="Mysoft.Crm.Application.Components" %>

<html>
<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"/>
	<cnt:AppHeader id="crmHeader" runat="server" />

	<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
<link rel="stylesheet" type="text/css" href="/_common/styles/dialogs.css">
<script language="javascript" src="/_controls/settings.aspx"></script>
<script language="javascript" src="/_forms/addrelated.js"></script>
<script language="javascript" src="/_controls/util/util.js"></script>
<script language="javascript" src="/_controls/number/number.js"></script>

	<link rel="stylesheet" type="text/css" href="lookupdialogs.css">
	<script language="javascript" src="lookupdialogs.js"></script>
	
	<script language="JavaScript">
<%
		RenderCreatePrivileges();
%>	
		_mode = <%=(uint)Mode%>;
	
		function applychanges()
		{
			window.returnValue = buildReturnValue( tblSelected.rows );
			window.close();
		}
		
		function cancel()
		{
			window.close();
		}
	
		function window.onload()
		{ 
			appendExistingItems();
			if ( !checkMode( _mode, LookupBrowse ) )
			{
				findValue.focus();
			}
		}
	
		function appendExistingItems()
		{
			var args = this.dialogArguments;
			if ( args == null ) return;
			if ( args.items == null ) return;
			var items = args.items;
			
			var len = items.length;
			for ( var i = 0; i < len; i++ )
			{
				var item = items[i];
				appendItem( item.getAttribute("oid"), item.getAttribute("otype"), item.innerHTML )
			}
			
			setNavigationState();
		}
		
		function resultsReady()
		{
			if ( frmResults.document.readyState == "complete" )
			{
				document.body.style.cursor = "auto";
				
				if ( !checkMode( _mode, LookupBrowse ) )
				{
					btnGo.disabled = false;
				}
			
				setNavigationState();
			}
		}
		
		//	remove the selected items from the right side
		//
		function removeSelected()
		{
			var items = tblSelected.selectedItems;
			for ( var i = 0; i < items.length; i++ )
			{
				items[i].removeNode( true )
			}
			
			//	clear the selected items collection
			//
			items.splice( 0, items.length );
			
			//	make sure that there there is something selected
			//  if there are still items left
			//
			if ( tblSelected.rows.length > 0 )
			{					
				selectItem( tblSelected, tblSelected.rows[0], true );
			}
			
			setNavigationState();
		}
		
		//	check if the entity is already selected
		//
		function duplicateSelection( oid )
		{
			var len = tblSelected.rows.length;
			for ( var i = 0; i < len; i++ )
			{
				if ( tblSelected.rows[i].oid == oid )
				{
					return true;
				}
			}
			return false;
		}
		
		function appendItem( id, type, html )
		{
			var tr		= tblSelected.insertRow();
			tr.oid		= id;
			tr.otype	= type;

			var td	= tr.insertCell();
			td.className	= "sel";
			td.noWrap		= true;
			td.innerHTML	= html;

			if ( tr.rowIndex == 0 )
			{	
				selectItem( tblSelected, tr, false );
			}
		}
		
		//	append all selected items from the left to the right
		//
		function appendSelected()
		{
			if (frmResults.tblResults == undefined)
			{
				return;
			}
			
			var items = frmResults.tblResults.selectedItems;
			if ( items )
			{
				var len	= items.length;

				for ( var i = 0; i < len; i++ )
				{
					var o = items[i];

					//	if this item isn't a duplicate selection then add it
					//
					if ( !duplicateSelection( o.oid ) )
					{
						appendItem( o.oid, o.otype, o.firstChild.innerHTML );
					}
				}
				
				setNavigationState();
			}
		}
		
		function setNavigationState()
		{
			if (frmResults.tblResults != undefined)
			{
				btnProperties.disabled = ( frmResults.tblResults.rows.length == 0 );
				btnAppend.disabled = ( frmResults.tblResults.rows.length == 0 );
				btnRemove.disabled = ( tblSelected.rows.length == 0 );
			
				tblNoRecords.runtimeStyle.display = ( tblSelected.rows.length == 0 ? "" : "none" );
			}
		}
	</script>
</head>

<body>
	<frm:DialogForm id="crmForm" runat="server">
		<table cellspacing="0" cellpadding="0" width="100%" height="100%">
			<tr>
				<td class="search">
					<% RenderSearchHeader(); %>
				</td>
			</tr>
			<tr>
				<td>
					<table height="100%" width="100%" id="tblFind" cellpadding="0" cellspacing="0">
						<tr height="20">
							<td>可用记录:</td><!- 汉化//^^->
							<td></td>
							<td>选中记录:</td><!- 汉化//^^->
						</tr>
						<tr>
							<td width="45%">
								<% RenderResultsFrame(); %>
							</td>
							<td width="60" align="center">
								<button disabled="true" tabindex="5" id="btnAppend" style="width: 40px;" onclick="appendSelected()" title="<%= CurrentResourceManager.GetString("ToolTip_Lookup_Add") %>">&gt;&gt;</button>
								<p>
								<button disabled="true" tabindex="6" id="btnRemove" style="width: 40px;" onclick="removeSelected();" title="<%= CurrentResourceManager.GetString("ToolTip_Lookup_Remove") %>">&lt;&lt;</button>
							</td>
							<td>
								<div id="rtnObjList" class="objects">
									<table hidefocus="true" tabindex="7" id="tblSelected" cellpadding="2" cellspacing="0" width="100%" onclick="clickItem( this )" ondblclick="removeSelected()"  onkeydown="listKeyDown(this)"></table>
									
									<table class="inlineMsg" id="tblNoRecords">
										<tr>
											<td class="inlineMsg" align="center">没有记录被选中。</td><!-汉化//^^ ->
										</tr>
									</table>
								</div>
							</td>
						</tr>
						<tr height="20" style="padding-top: 10px;">
							<td colspan="3" nowrap>
								<% RenderButtons(); %>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</frm:DialogForm>
</body>
</html>
